#include "SSD1306Wire.h"
SSD1306Wire display(0x3c, 2, 14);
#include <dht11.h>
// SSD1306Wire 显示 图片
// 图片 分辨率 降低

dht11 DHT11;
// const int
// SSD1306Wire display(0x3c,2,14);
const uint8_t wen[] = {
    0x00, 0x00, 0xC4, 0x1F, 0x48, 0x10, 0x48, 0x10, 0xC1, 0x1F, 0x42, 0x10, 0x42, 0x10, 0xC8, 0x1F,
    0x08, 0x00, 0xE4, 0x3F, 0x27, 0x25, 0x24, 0x25, 0x24, 0x25, 0x24, 0x25, 0xF4, 0x7F, 0x00, 0x00,
    /*"温",0*/};
const uint8_t du[] = {
    0x80, 0x00, 0x00, 0x01, 0xFC, 0x7F, 0x44, 0x04, 0x44, 0x04, 0xFC, 0x3F, 0x44, 0x04, 0x44, 0x04,
    0xC4, 0x07, 0x04, 0x00, 0xF4, 0x0F, 0x24, 0x08, 0x42, 0x04, 0x82, 0x03, 0x61, 0x0C, 0x1C, 0x70, /*"度",1*/
};
const uint8_t shi[] = {
    0x00, 0x00, 0xE4, 0x1F, 0x28, 0x10, 0x28, 0x10, 0xE1, 0x1F, 0x22, 0x10, 0x22, 0x10, 0xE8, 0x1F,
    0x88, 0x04, 0x84, 0x04, 0x97, 0x24, 0xA4, 0x14, 0xC4, 0x0C, 0x84, 0x04, 0xF4, 0x7F, 0x00, 0x00,
    /*"湿",2*/};

//  G:\edgeDownload\wenduji2_32.bmp(0)

// const uint8_t wenduji[]={

// 0x00,0x06,0x7C,0x00,0x40,0x64,0xCE,0x00,0xC0,0x66,0xBE,0x00,0x00,0x1F,0xAA,0x01,
// 0x80,0x11,0xAA,0x01,0xB0,0xF1,0xAA,0x01,0xA0,0xB1,0xAA,0x01,0x00,0x1F,0x6A,0x00,
// 0xC0,0x2E,0xAA,0x07,0xC0,0x60,0xEA,0x03,0x00,0x06,0xAA,0x07,0x00,0x04,0xEA,0x03,
// 0x00,0x00,0xAA,0x07,0x00,0x00,0xEA,0x07,0x00,0x00,0xAA,0x07,0x00,0x00,0xAA,0x07,
// 0x00,0x00,0xAA,0x07,0x00,0x00,0xAA,0x07,0x00,0x00,0xEA,0x00,0x00,0x00,0xAA,0x01,
// 0x00,0x00,0xAB,0x03,0x00,0x80,0xED,0x02,0x00,0xC0,0xC6,0x07,0x00,0xC0,0x83,0x05,
// 0x00,0x40,0x01,0x0D,0x00,0x40,0x01,0x0F,0x00,0x40,0x03,0x0D,0x00,0xC0,0x83,0x05,
// 0x00,0xC0,0xEE,0x06,0x00,0x80,0x7D,0x03,0x00,0x00,0xC7,0x01,0x00,0x00,0xFC,0x00

// };
// "G:\edgeDownload\wenduji2_32.bmp",0

//  未命名文件(0)
const uint8_t wenduji[] = {

    0x00, 0x00, 0xC0, 0x05, 0x40, 0x39, 0x40, 0x09, 0x40, 0x39, 0x40, 0x01, 0x40, 0x01, 0x40, 0x01,
    0x40, 0x01, 0xC0, 0x01, 0xC0, 0x01, 0xE0, 0x03, 0xE0, 0x03, 0xE0, 0x03, 0xE0, 0x03, 0x00, 0x00,
    // "未命名文件",0

};

// http://www.taichi-maker.com/homepage/iot-development/iot-dev-reference/esp8266-iot-dev-ref/esp8266-sensor-ref/dht11-esp8266-ref/
void setup()
{
  // put your setup code here, to run once:
  Serial.begin(115200); //设置波特率为115200
  display.init();
  Serial.println("\n");
  Serial.println("esp8266读取DHT11传感器数值 ");
  Serial.println("串口会分别打印当前湿度（%），当前摄氏度温度，当前华氏度温度和当前开式温度 ");
  Serial.print("DHT11库文件版本: ");
  Serial.println(DHT11LIB_VERSION);
  Serial.println();
}

void readDhtAndShow(int dhtIo)
{

  DHT11.read(dhtIo);
  // put your main code here, to run repeatedly:
  display.flipScreenVertically();
  // display.setFont(ArialMT_Plain_16);
  display.clear();
  // https://blog.csdn.net/xuanyuanlei1020/article/details/50991409
  display.drawIco16x16(0, 0, wen, 0);
  display.drawIco16x16(20, 0, du, 0);
  // display.drawString(40,0,to_String(DHT11.temperature));
  // size of array 's' has non-integral type '<unresolved overloaded function type>'
  //
  display.drawString(40, 0, String(DHT11.temperature));
  // int 转化   string c++
  // converting to 'const String' from initializer list would use explicit constructor 'String::String(int, unsigned char)'
  //
  display.drawIco16x16(0, 20, shi, 0);
  display.drawIco16x16(20, 20, du, 0);
  //  display.drawString(40,20,String::String(DHT11.humidity));
  // display.drawIco32x32(110,13,wenduji,0);
  // cannot call constructor 'String::String' directly [-fpermissive]
  //

  display.drawString(40, 20, String(DHT11.humidity));
  //  display.drawIco16x16(70,10,wendujiShang,0);
  //  display.drawIco16x16(70,25,wendujiXia,0);

  display.drawIco16x16(60, 10, wenduji, 0);
  display.display();
  delay(500);
}

// int dhtIo=1;
// 1 不行

// int dhtIo=2;
// loop 里面 ++ 知道了 dht io 是 5 

int dhtIo = 5;

void testRead(int dhtIo)
{
  DHT11.read(dhtIo);
  Serial.printf("dhtIo:  %d\n", dhtIo);
  //  测出来 是 5 ，dht 不过好在 去读这些引脚的时候 不会造成事故

  //  Serial.printf("i:  %d\n",i);
  Serial.print("当前湿度 (%): ");
  Serial.println((float)DHT11.humidity, 2);

  Serial.print("当前温度 (℃): ");
  Serial.println((float)DHT11.temperature, 2);
  dhtIo++;
  delay(500);
}

void testRead2()
{
  // for(int i=0;i<10;i++){
  //     DHT11.read(i);

  //    Serial.printf("i:  %d\n",i);
  //   Serial.print("当前湿度 (%): ");
  // Serial.println((float)DHT11.humidity, 2);

  // Serial.print("当前温度 (℃): ");
  // Serial.println((float)DHT11.temperature, 2);
  // delay(500);
  // }
}

void loop()
{

  // int readIo=
  //  DHT11.read(5);
  // testRead(dhtIo);
  readDhtAndShow(dhtIo);
}
